package com.fudan.backend.dao;

import com.fudan.backend.handler.IdTypeHandler;
import com.fudan.backend.handler.ListTypeHandler;
import com.fudan.backend.pojo.CommodityModifyRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommodityModifyRequestDao {
    @Results(id="commodityModifyRequestResultMap", value={
            @Result(column = "commodity_modify_request_id", property = "commodityModifyRequestId", typeHandler = IdTypeHandler.class),
            @Result(column = "commodity_id", property = "commodityId", typeHandler = IdTypeHandler.class),
            @Result(column = "store_id", property = "storeId", typeHandler = IdTypeHandler.class),
            @Result(column = "category_id", property = "categoryId", typeHandler = IdTypeHandler.class),
            @Result(column = "pictures", property = "pictures", typeHandler = ListTypeHandler.class),
    })
    @Select("select * from t_commodity_modify_request")
    List<CommodityModifyRequest> selectAllCommodityModifyRequest();

    @ResultMap("commodityModifyRequestResultMap")
    @Select("select * from t_commodity_modify_request where commodity_modify_request_id = #{commodityModifyRequestId}")
    CommodityModifyRequest selectCommodityModifyRequestByCommodityModifyRequestId(String commodityModifyRequestId);

    @ResultMap("commodityModifyRequestResultMap")
    @Select("select * from t_commodity_modify_request where store_id = #{storeId}")
    List<CommodityModifyRequest> selectAllCommodityModifyRequestByStoreId(String storeId);

    @Insert("insert into t_commodity_modify_request values " +
            "(#{commodityModifyRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{initiateTime}, #{processTime}, #{commodityId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{commodityName}, #{storeId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, #{categoryId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, #{price}, #{stocks}, " +
            "#{pictures, typeHandler=com.fudan.backend.handler.ListTypeHandler}, #{description}, #{status}, #{info})")
    int insertCommodityModifyRequest(CommodityModifyRequest commodityModifyRequest);

    @Update("update t_commodity_modify_request set " +
            "process_time = #{processTime}, commodity_name = #{commodityName}, " +
            "category_id = #{categoryId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "price = #{price}, stocks = #{stocks}, " +
            "pictures = #{pictures, typeHandler=com.fudan.backend.handler.ListTypeHandler}, " +
            "description = #{description}, status = #{status}, info = #{info} " +
            "where commodity_modify_request_id = #{commodityModifyRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}")
    int updateCommodityModifyRequest(CommodityModifyRequest commodityModifyRequest);

}
